package cn.wolfcode.controller;


import cn.wolfcode.domain.Dept;
import cn.wolfcode.domain.Result;
import cn.wolfcode.service.DeptService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/depts")
public class DeptController {

    @Autowired
    private DeptService deptService;

    @GetMapping
    public Result getDeptList() {
        //调用 Service 返回数据
        return Result.success(deptService.getDeptList());
    }

    @DeleteMapping("/{id}")
    public Result deleteDept(@PathVariable Long id) {
        deptService.delete(id);
        return Result.success();
    }

    @PostMapping
    public Result addDept(@RequestBody Dept dept) {
        deptService.add(dept);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getDept(@PathVariable Long id) {
        Dept dept=deptService.getById(id);
        return Result.success(dept);
    }
    @PutMapping
    public Result updateDept(@RequestBody Dept dept) {
        deptService.update(dept);
        return Result.success();
    }
}
